const compressing = require('compressing');
const mkdirp = require('mkdirp');

const fs = require('fs');
const handleError = console.log
const handleFinish = console.log


function tar() {
    const tarStream = new compressing.tar.Stream();
    tarStream.addEntry('source');

    tarStream
        .on('error', handleError)
        .pipe(fs.createWriteStream('up.tar'))
        .on('error', handleError);
}

function gunzip() {

    const onEntry = (header, stream, next) => {
        stream.on('end', next);

        // header.type => file | directory
        // header.name => path name

        if (header.type === 'file') {
            stream.pipe(fs.createWriteStream(path.join(destDir, header.name)));
        } else { // directory
            mkdirp(path.join(destDir, header.name), err => {
                if (err) return handleError(err);
                stream.resume();
            });
        }
    }

    new compressing.tgz.UncompressStream({ source: 'chunk-a.gz' })
        .on('error', handleError)
        .on('finish', handleFinish) // uncompressing is done
        .on('entry', onEntry);

    // It's a writable stream, so you can pipe to it
    // fs.createReadStream('file/path/to/uncompress')
    //     .on('error', handleError)
    //     .pipe(new compressing.tgz.UncompressStream())
    //     .on('error', handleError)
    //     .on('finish', handleFinish) // uncompressing is done
    //     .on('entry', onEntry);
}

gunzip()